package com.wman.mvvm;

import android.widget.TextView;

import com.wman.data.DataCenter;

import java.util.List;

/**
 * @ProjectName: wman
 * @Package: com.wman.mvp
 * @ClassName: Presenter
 * @Description: java类作用描述
 * @Author: wman
 * @CreateDate: 2019/11/11 11:57
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/11/11 11:57
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class ViewModel {
    TextAttr str1 = new TextAttr();
    TextAttr str2 = new TextAttr();

    ViewModel(ViewBinder binder, TextView textView1, TextView textView2) {
        binder.bind(textView1, str1);
        binder.bind(textView2, str2);
    }

    void load() {
        List<String> data = DataCenter.getData();
        str1.setText(data.get(0));
        str2.setText(data.get(1));
    }

    static class TextAttr {
        private String text;
        private OnChangeListener listener;

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
            if (listener != null) {
                listener.onChange(text);
            }
        }

        public void setOnChangeListener(OnChangeListener listener) {
            this.listener = listener;
        }

        interface OnChangeListener {
            void onChange(String text);
        }
    }
}
